//
// SourceFiles.cs: This file contains the definition for SourceFiles class.
//
// Author: BDS - thinktecture 
//
using System;
using System.Collections;

namespace Thinktecture.Tools.Web.Services.CodeGeneration
{
	/// <summary>
	/// SourceFiles class is a container for SourceFile type. This inherits the CollectionBase class.
	/// </summary>
	public class SourceFiles : CollectionBase
	{
		#region Constructors
		
		/// <summary>
		/// Default constructor. Initializes the members to their default values.
		/// </summary>
		public SourceFiles()
		{
		}

		#endregion

		#region Methods

		/// <summary>
		/// Adds a new SourceFile object to the collection
		/// </summary>
		/// <param name="pitem">SourceFile object</param>
		public void Add(SourceFile pitem)
		{
			// Check the parameters.
			if(pitem == null)
				throw new ArgumentNullException("pitem");

			this.InnerList.Add(pitem);
		}
		
		/// <summary>
		/// Adds a new SourceFile object to the collection.
		/// </summary>
		/// <param name="pfilename">Target file name for the source file.</param>
		/// <param name="psourcecode">Source code for the file.</param>
		public void Add(string pfilename, string psourcecode)
		{
			// Chech the parameters.
			if(pfilename == null)
				throw new ArgumentNullException("pfilename");
			if(psourcecode == null)
				throw new ArgumentNullException("psourcecode");

			Add(new SourceFile(pfilename,psourcecode));
		}
		
		#endregion

		#region Property Getters/Setters
		
		public SourceFile this[int index]
		{
			get { return ((SourceFile)this.InnerList[index]); }
			set
			{
				// BDS: Check the input value before assigning.
				if(value == null)
					throw new ArgumentNullException("SourceFile");

				this.InnerList[index] = value;
			}

		}

		/// <summary>
		/// This property searchs for the Asmx Declarative file in the source files collection and 
		/// returns it.
		/// </summary>
		public SourceFile AsmxFile
		{
			get
			{
				foreach(SourceFile f in InnerList)
				{
					if(f.AsmxDeclarative)
						return f;
				}
				return null;
			}
		}

		/// <summary>
		/// This property searchs for the service implementation file in the source files collection and 
		/// returns it.
		/// </summary>
		public SourceFile ServiceImplementation
		{
			get
			{
				foreach(SourceFile f in InnerList)
				{
					if(f.ServiceImplementation)
						return f;
				}
				return null;
			}
		}

		/// <summary>
		/// This property searchs for the asmx help file in the source files collection and 
		/// returns it.
		/// </summary>
		public SourceFile AspxHelpFile
		{
			get
			{
				foreach(SourceFile f in InnerList)
				{
					if(f.AspxHelpPage)
						return f;
				}
				return null;
			}
		}

		/// <summary>
		/// This property searchs for the proxy help file in the source files collection and 
		/// returns it.
		/// </summary>
		/// <author>CSC</author>
		public SourceFile ProxyFile
		{
			get
			{
				foreach(SourceFile f in InnerList)
				{
					if(f.ProxyImplementation)
						return f;
				}
				return null;
			}
		}
		#endregion
	}
}
